<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | create by allen.qiang
// +----------------------------------------------------------------------


/**
 * 超值选购操作功能
 * @package  htdocs
 * @subpackage  quanliadmin
 * create by allen.qiang
 */

require 'module/base/promotionHandler.class.php';

class pa_selection {
	//入口
	public function execute(){
		global $G_PGLOB;
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		switch ($operFlg){
			case 1:
				$this->init();
				break;
			case 2:
			case 3:
				$this->showEdit();
				break;
            case 4:
                $this->showInfo();
                break;
			default:
				$G_PGLOB->smarty->assign('error_msg','参数错误');
				$G_PGLOB->smarty->display('comm/errorDisplay.tpl');
				break;
		}
	}
	//初始化列表页
	private function init (){
		global $G_PGLOB;
		$G_PGLOB->smarty->display('promotion/selectionList.tpl');
	}
	
	//新增、编辑套装页初始化
	private function showEdit (){
		global $G_PGLOB;
		$operFlg = isset($_REQUEST['operFlg']) ? $_REQUEST['operFlg'] : null;
		$choice_type = isset($_REQUEST['choice_type']) ? $_REQUEST['choice_type'] : null;//(邮购或网站)
		$goodsChoiceID = isset($_REQUEST['goodsChoiceID']) ? $_REQUEST['goodsChoiceID'] : null;
		
		//实例化字典表操作公共类
		$itemHandler = new itemHandler( $G_PGLOB->DBCA );
		
		$arg_arr = array('item' => 6);
		//查询分类信息 
		$item_array = $itemHandler->searchItemList( $arg_arr );//6为超值选购分类
		
		$G_PGLOB->smarty->assign('item', $item_array);//分类
		
		$G_PGLOB->smarty->assign('choice_type', $choice_type);
		if ($operFlg == 2){
			//显示新增
			$G_PGLOB->smarty->assign('operFlg', 1);
		}else {
			//显示编辑
			$G_PGLOB->smarty->assign('operFlg', 2);
			
			$promotionHandler = new promotionHandler($G_PGLOB->DBCA);
			
			/*------------------表单部分start-------------------------*/
			
			$importData = array('goodsChoiceID'=>$goodsChoiceID);
			
			$result_search = $promotionHandler->searchSelection($importData);
			
			if ($result_search['code'] != 200 || empty($result_search['message']['data'])){
				$G_PGLOB->smarty->assign('error_msg','该选购不存在或已被删除');
				$G_PGLOB->smarty->display('comm/errorDisplay.tpl');
				die();
			}
			
			if (!empty($result_search['message']['data'])){
				$G_PGLOB->smarty->assign('selectionInfo', $result_search['message']['data'][0]);
			}
			
			/*------------------表单部分end-------------------------*/
			
			$importData = array('goodsChoiceID'=>$goodsChoiceID);
			
			//得到超值选购商品
			$result_detail = $promotionHandler->searchSelectionDetailAll($importData);
				
			if ($result_detail['code'] == 200 && !empty($result_detail['message']['data'])){
				$detail_info = $result_detail['message']['data'];
			}
				

			$G_PGLOB->smarty->assign('selectionGoodsInfo', $detail_info);
		}
        $G_PGLOB->smarty->display('promotion/selectionDetail.tpl');
	}

    //显示详情页
    private function showInfo (){
        global $G_PGLOB;

        if(!isset($_REQUEST['goodsChoiceID']) || !is_numeric($_REQUEST['goodsChoiceID'])  ){
            $G_PGLOB->smarty->assign('error_msg','参数错误');
            $G_PGLOB->smarty->display('promotion/selectionInfo.tpl');
            die();
        }

        //获取超值选购主表信息
        $result_info = $G_PGLOB->DBCA->stmt_query("SELECT * FROM promotion_selection WHERE goodsChoiceID = ?",'i',$_REQUEST['goodsChoiceID']);
        if(!$result_info){
            $G_PGLOB->smarty->assign('error_msg','未获取超值选购信息');
            $G_PGLOB->smarty->display('promotion/selectionInfo.tpl');
            die();
        }

        //得到超值选购商品
        $promotionHandler = new promotionHandler($G_PGLOB->DBCA);
        $result_detail = $promotionHandler->searchSelectionDetailAll($_REQUEST);

        if ($result_detail['code'] == 200 && !empty($result_detail['message']['data'])){
            $detail_info = $result_detail['message']['data'];
        }
        $G_PGLOB->smarty->assign('selectionGoodsInfo', $detail_info);


        //实例化字典表操作公共类
        $itemHandler = new itemHandler( $G_PGLOB->DBCA );
        
        $arg_arr = array('item'   => 6,
        				 'itemID' => $result_info[0]->itemID);
        //查询分类信息
        $item_array = $itemHandler->searchItemList( $arg_arr );//6为超值选购分类
        
        $G_PGLOB->smarty->assign('itemName', $item_array[0]->itemName);//分类

        $G_PGLOB->smarty->assign('selectionInfo', $result_info[0]);
        $G_PGLOB->smarty->assign('goodsChoiceID',$_REQUEST['goodsChoiceID']);
        $G_PGLOB->smarty->display('promotion/selectionInfo.tpl');
    }

}